/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.dto.platform.EstateApplicationFormDTO;
import org.springblade.modules.admin.vo.EstateApplicationFormHomePageVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.modules.admin.vo.EstateApplicationFormVO;
import org.springblade.modules.admin.service.IEstateApplicationFormService;
import org.springblade.modules.admin.vo.CommonSelectVO;
import org.springblade.modules.admin.vo.platform.ApplicationFormVO;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 物业项目关联申请记录表 控制器
 *
 * @author ysq
 * @since 2022-05-27
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/estate/application/form")
@Api(value = "物业项目关联申请记录表", tags = "物业项目关联申请记录表接口")
public class EstateApplicationFormController extends BladeController {

	private final IEstateApplicationFormService estateApplicationFormService;

	/**
	 * 自定义分页 物业项目关联申请记录表
	 */
	@PostMapping("/estate/page")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "分页", notes = "传入estateApplicationForm")
	public R<IPage<EstateApplicationFormVO>> page(@RequestBody EstateApplicationFormVO estateApplicationForm, @RequestBody Query query) {
		IPage<EstateApplicationFormVO> pages = estateApplicationFormService.selectEstateApplicationFormPage(Condition.getPage(query), estateApplicationForm);
		return R.data(pages);
	}

	/**
	 * 自定义分页 物业项目关联申请记录表
	 */
	@PostMapping("/page")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "项目关联申请页列表", notes = "传入estateApplicationForm")
	public R<IPage<ApplicationFormVO>> list(@RequestBody EstateApplicationFormDTO estateApplicationFormDTO) {
		IPage<ApplicationFormVO> pages = estateApplicationFormService.selectEstateApplicationFormPage(estateApplicationFormDTO);
		return R.data(pages);
	}

	/**
	 * 新增物业项目关联申请
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "新增物业项目关联申请")
	public R saveForm(@Valid @RequestBody EstateApplicationFormVO estateApplicationFormVO) {
		return R.status(estateApplicationFormService.saveForm(estateApplicationFormVO));
	}

	@GetMapping("/select/name")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "项目名称下拉选择数据")
	public R<List<Map<String, Object>>> selectName(@ApiParam(value = "申请记录id") @RequestParam(required = false) Long formId) {
		return R.data(estateApplicationFormService.selectName(formId));
	}

	@GetMapping("/select/elevator")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "电梯下拉选择数据")
	public R<List<CommonSelectVO>> selectElevator(@ApiParam(value = "申请记录id") @RequestParam(required = false) Long formId) {
		return R.data(estateApplicationFormService.selectElevator(formId));
	}

	@GetMapping("/select/user")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "申请人下拉选择数据")
	public R<List<Map<String, Object>>> selectUser() {
		return R.data(estateApplicationFormService.selectUser());
	}

	/**
	 * 首页代办列表
	 */
	@GetMapping("/home/page")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "分页", notes = "传入estateApplicationForm")
	public R<IPage<EstateApplicationFormHomePageVO>> homePage(EstateApplicationFormVO estateApplicationForm, Query query) {
		IPage<EstateApplicationFormHomePageVO> pages = estateApplicationFormService.selectEstateApplicationFormHomePageVO(Condition.getPage(query), estateApplicationForm);
		return R.data(pages);
	}

}
